<template>
  <div class="container">
    <van-sticky :offset-top="0">
      <van-nav-bar
        :title="list[0] ? list[0].category.name : '分类'"
        left-text="返回"
        left-arrow
        @click-left="back"
      />
    </van-sticky>
    <van-search v-model="value" placeholder="请输入搜索关键词" />
    <van-card
      v-for="item in list"
      :key="item.id"
      :desc="item.desc"
      :title="item.name"
      :thumb="item.coverImage | dalImg"
      :thumb-link="'/#/adetail?id=' + item.id"
    >
      <template #bottom>
        <van-tag plain type="danger">{{
          $moment(list.createdAt).format("YYYY-MM-DD")
        }}</van-tag>
      </template>
      <template #footer>
        <van-tag plain type="danger">浏览量{{ amount }}</van-tag>
      </template>
    </van-card>
  </div>
</template>

<script>
import { loadarticle_zixun } from "../services/zixun";
export default {
  data() {
    return {
      list: [],
      value: "",
      amount: 0,
    };
  },
  async created() {
    this.loadarticle();
  },
  methods: {
    back() {
      window.history.go(-1);
    },
    async loadarticle(search) {
      const res = await loadarticle_zixun(this.$route.query.id, search);
      this.list = res.data;
      this.amount = Math.floor(Math.random() * 100);
    },
  },
  watch: {
    value(v) {
      this.loadarticle(v);
    },
  },
};
</script>

<style>
</style>